// pages/supplier/withdrawalDetails/withdrawalDetails.js
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        hasMore:true,
        pageSize:10,
        pageNo:1,
        orderList:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            supplierId:options.supplierId
        })
        this.getData()
    },

    getData(){
        let that = this;
        that.setData({
            pageNo: 1,
            hasMore:true
        });
        wx.showLoading({
            title: '加载中...',
          })
          var url = api.supplier.withdrawList + "?pageNo=" +that.data.pageNo + '&pageSize=' + that.data.pageSize+ '&supplierId=' + that.data.supplierId;
          util.request(url,'put').then(function(res) {
            that.setData({
                orderList: res.result
            });
            if (res.result.length < that.data.pageSize) {
                that.setData({
                    hasMore: false,
                })
            }
            wx.stopPullDownRefresh();
            wx.hideLoading()
        }).catch(err=>{
            console.log(err)
            wx.hideLoading()
            wx.stopPullDownRefresh() 
        })
    },
    loadMore: function() {
        var that = this;
        if (!this.data.hasMore) return
        wx.showLoading({
            title: '加载中...',
        })
        var url = api.supplier.withdrawList + "?pageNo=" + (++that.data.pageNo) + '&pageSize=' + that.data.pageSize+ '&supplierId=' + that.data.supplierId;
        util.request(url,'put').then(function(res) {
            if (res.code == 200) {
                that.setData({
                    orderList: that.data.orderList.concat(res.result)
                });
                if (res.result.length < that.data.pageSize) {
                    that.setData({
                        hasMore: false,
                    })
                }
                wx.hideLoading()
            }
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.getData()
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        this.loadMore()
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})